package com.ruoyi.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.entity.SafetyTrainingRecord;
import com.ruoyi.exam.service.ISafetyTrainingRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 个人安全教育培训档案，用于记录个人的安全教育培训信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/exam/training")
public class SafetyTrainingRecordController extends BaseController
{
    @Autowired
    private ISafetyTrainingRecordService safetyTrainingRecordService;

    /**
     * 查询个人安全教育培训档案，用于记录个人的安全教育培训信息列表
     */
    @PreAuthorize("@ss.hasPermi('exam:training:list')")
    @GetMapping("/list")
    public TableDataInfo list(SafetyTrainingRecord safetyTrainingRecord)
    {
        startPage();
        List<SafetyTrainingRecord> list = safetyTrainingRecordService.selectSafetyTrainingRecordList(safetyTrainingRecord);
        return getDataTable(list);
    }

    /**
     * 导出个人安全教育培训档案，用于记录个人的安全教育培训信息列表
     */
    @PreAuthorize("@ss.hasPermi('exam:training:export')")
    @Log(title = "个人安全教育培训档案，用于记录个人的安全教育培训信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SafetyTrainingRecord safetyTrainingRecord)
    {
        List<SafetyTrainingRecord> list = safetyTrainingRecordService.selectSafetyTrainingRecordList(safetyTrainingRecord);
        ExcelUtil<SafetyTrainingRecord> util = new ExcelUtil<SafetyTrainingRecord>(SafetyTrainingRecord.class);
        util.exportExcel(response, list, "个人安全教育培训档案，用于记录个人的安全教育培训信息数据");
    }

    /**
     * 获取个人安全教育培训档案，用于记录个人的安全教育培训信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:training:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(safetyTrainingRecordService.selectSafetyTrainingRecordById(id));
    }

    /**
     * 新增个人安全教育培训档案，用于记录个人的安全教育培训信息
     */
    @PreAuthorize("@ss.hasPermi('exam:training:add')")
    @Log(title = "个人安全教育培训档案，用于记录个人的安全教育培训信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SafetyTrainingRecord safetyTrainingRecord)
    {
        safetyTrainingRecord.setUserId(SecurityUtils.getUserId());
        return toAjax(safetyTrainingRecordService.insertSafetyTrainingRecord(safetyTrainingRecord));
    }

    /**
     * 修改个人安全教育培训档案，用于记录个人的安全教育培训信息
     */
    @PreAuthorize("@ss.hasPermi('exam:training:edit')")
    @Log(title = "个人安全教育培训档案，用于记录个人的安全教育培训信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SafetyTrainingRecord safetyTrainingRecord)
    {
        return toAjax(safetyTrainingRecordService.updateSafetyTrainingRecord(safetyTrainingRecord));
    }

    /**
     * 删除个人安全教育培训档案，用于记录个人的安全教育培训信息
     */
    @PreAuthorize("@ss.hasPermi('exam:training:remove')")
    @Log(title = "个人安全教育培训档案，用于记录个人的安全教育培训信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(safetyTrainingRecordService.deleteSafetyTrainingRecordByIds(ids));
    }
}
